package dao

import bean.{Orders, OrdersToMysql, Store, User}
import org.apache.spark.sql.Dataset
import util.SparkUtil

import java.util.Properties

/**
 * @作者 YanTianCheng
 * @时间 2024/2/15 22:32
 * @文件: BatchDataDao
 * @项目 dao
 */
class BatchDataDao {
  private val spark = SparkUtil.takeSpark()
  import spark.implicits._
  //获取history_orders表中的数据
  def getTakeawayData(): Dataset[OrdersToMysql] = {
    val props = new Properties()
    props.setProperty("user", "root")
    props.setProperty("password", "Niit@123")
    val OrdersInfoDS: Dataset[OrdersToMysql] = spark.read.jdbc(
      "jdbc:mysql://node1:3306/Graduation?useUnicode=true&characterEncoding=utf8",
      "ordering_Information",
      props
    ).as[OrdersToMysql]
    //返回值
    OrdersInfoDS
  }
  def getTakeawayData2(): Dataset[Store] = {
    val props = new Properties()
    props.setProperty("user", "root")
    props.setProperty("password", "Niit@123")
    val StoreInfoDS: Dataset[Store] = spark.read.jdbc(
      "jdbc:mysql://node1:3306/Graduation?useUnicode=true&characterEncoding=utf8",
      "Store_Information",
      props
    ).as[Store]
    StoreInfoDS
  }

  def getTakeawayData3(): Dataset[User] = {
    val props = new Properties()
    props.setProperty("user", "root")
    props.setProperty("password", "Niit@123")
    val UserInfoDS: Dataset[User] = spark.read.jdbc(
      "jdbc:mysql://node1:3306/Graduation?useUnicode=true&characterEncoding=utf8",
      "user_information",
      props
    ).as[User]
    UserInfoDS
  }
  def getTakeawayData4(): Dataset[Orders] = {
    val props = new Properties()
    props.setProperty("user", "root")
    props.setProperty("password", "Niit@123")
    val OrderSimulationDS: Dataset[Orders] = spark.read.jdbc(
      "jdbc:mysql://node1:3306/Graduation?useUnicode=true&characterEncoding=utf8",
      "Orders_Simulation",
      props
    ).as[Orders]
    OrderSimulationDS
  }



}
